<template>
  <div class="navbar">
    <!-- 导航栏内容 -->
    <div class="nav_content">
      <span class="label_title">临沂沂州实验信息技术检测</span>
      <span class="label_user" v-if="showUser">{{ userName }}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: "Navbar",
  // 可以添加一些逻辑
  data() {
    return {
      showUser: false,
      userName: "",
    }
  },
  watch: {
    // 监听路由对象中的变化
    $route: {
      handler: function (to) {
        // 路由变化时的处理逻辑
        if (to.path != "login") {
          this.showUser = true;
          this.userName = sessionStorage.getItem("user") || null;
        } else {
          this.showUser = false;
          sessionStorage.removeItem("user")
        }
      },
      // 设置为深度监听
      deep: true,
    },
  },
};
</script>

<style lang="less" scoped>
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  opacity: 1;
  z-index: 200;
  background-color: #f1f2f3;
  border-bottom: 1px solid #eee;
  /* 其他样式 */
}
.nav_content {
  /* 导航栏样式 */
  height: 50px;
  line-height: 50px;
  text-align: left;
  font-size: 28px;
  font-weight: bolder;
  padding: 0 20px;
  border-bottom: 1px solid #eee;
  color: #333;
  .label_user {
    margin-left: 10px;
    font-weight: 500;
    font-size: 20px;
    color: #aaa;
  }
}
</style>
